package beans;

import bookException.BookException;
import libs.UserValidation;
import classes.EditClass;
import entity.User;

public class EditBean extends GeneralBean{

	private EditClass editModel;
	
	
	public EditBean() {
		this.editModel = new EditClass();
	}
	
	public User getPerson(){
		User user = new User(
				getIntFromParam("id"),
				getStringFromParam("tbName"),
				getStringFromParam("tbSurname"),
				getStringFromParam("tbMiddlename"),
				getStringFromParam("tbMobile"),
				getStringFromParam("tbHomephone"),
				getStringFromParam("tbMail"),
				getStringFromParam("tbAddress")
		);
		
		if(UserValidation.validateUserForm(user))
			return user;	
		else
			return editModel.getPerson(getStringFromParam("id"));
	}
	
	
	public boolean getEditUser() {
		
		
		User user = new User(
				getIntFromParam("id"),
				getStringFromParam("tbName"),
				getStringFromParam("tbSurname"),
				getStringFromParam("tbMiddlename"),
				getStringFromParam("tbMobile"),
				getStringFromParam("tbHomephone"),
				getStringFromParam("tbMail"),
				getStringFromParam("tbAddress")
				
		);
		
		try {
			UserValidation.validateUser(user);
		} catch (BookException e) {
			this.setBookException(e);
			return false;
		}
		
		editModel.editPerson(user);	
		return true;
	}
}
